package com.yoso.thread;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.ThreadFactory;

/**
 * @author shizejin
 * @date 2021/12/31
 * @description:
 */
public class MyThreadFactory implements ThreadFactory {
    private final String name;
    /**
     * Constructs a new {@code Thread}.  Implementations may also initialize
     * priority, name, daemon status, {@code ThreadGroup}, etc.
     *
     * @param r a runnable to be executed by new thread instance
     * @return constructed thread, or {@code null} if the request to
     * create a thread is rejected
     */
    @Override
    public Thread newThread(@NotNull Runnable r) {
        return new Thread(r, name);
    }

    public MyThreadFactory(String name) {
        this.name = name;
    }
}
